//
//  ICMBalanceRepairEventTableViewCell.m
//  ICrEAM
//
//  Created by Cty on 2016/11/03.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMBalanceRepairEventTableViewCell.h"

@interface ICMBalanceRepairEventTableViewCell ()

@property (nonatomic, strong) UILabel *orderLabel;

@property (nonatomic, strong) UILabel *eventNumberLabel;

@property (nonatomic, strong) UILabel *eventNameLabel;

@property (nonatomic, strong) UILabel *workingTimeLabel;

@property (nonatomic, strong) UILabel *workingPriceLabel;

@property (nonatomic, strong) UILabel *repairTypeLabel;

@property (nonatomic, strong) UILabel *breakdownDiscribeLabel;

@property (nonatomic, strong) UILabel *labourPriceLabel;


@end

@implementation ICMBalanceRepairEventTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *repairEventCellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-ActualWidth(20), ActualHeight(25))];
        repairEventCellView.backgroundColor = BackgroundColor_Gray;
        [self.contentView addSubview:repairEventCellView];
        
        
        UILabel *orderLabel = [self createLabelWithText:@"1" frame:CGRectMake(0, ActualHeight(5), ActualWidth(60), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairEventCellView addSubview:orderLabel];
        self.orderLabel = orderLabel;
        
        UIView *secondSep = [[UIView alloc] initWithFrame:CGRectMake(orderLabel.rightEdge, 0, 1, repairEventCellView.height)];
        secondSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:secondSep];
        
        UILabel *eventNumberLabel = [self createLabelWithText:@"" frame:CGRectMake(secondSep.rightEdge, orderLabel.y, ActualWidth(145), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairEventCellView addSubview:eventNumberLabel];
        self.eventNumberLabel = eventNumberLabel;
        
        UIView *thirdSep = [[UIView alloc] initWithFrame:CGRectMake(eventNumberLabel.rightEdge, 0, 1, repairEventCellView.height)];
        thirdSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:thirdSep];
        
        UILabel *eventNameLabel = [self createLabelWithText:@"" frame:CGRectMake(thirdSep.rightEdge, orderLabel.y, ActualWidth(245), ActualHeight(15)) textAlignment:NSTextAlignmentLeft];
        [repairEventCellView addSubview:eventNameLabel];
        self.eventNameLabel = eventNameLabel;
        
        UIView *fourthSep = [[UIView alloc] initWithFrame:CGRectMake(eventNameLabel.rightEdge, 0, 1, repairEventCellView.height)];
        fourthSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:fourthSep];
        
        UILabel *workingTimeLabel = [self createLabelWithText:@"" frame:CGRectMake(fourthSep.rightEdge, orderLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [repairEventCellView addSubview:workingTimeLabel];
        self.workingTimeLabel = workingTimeLabel;
        
        UIView *fifthSep = [[UIView alloc] initWithFrame:CGRectMake(workingTimeLabel.rightEdge, 0, 1, repairEventCellView.height)];
        fifthSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:fifthSep];
        
        UILabel *labourPriceLabel = [self createLabelWithText:@"" frame:CGRectMake(fifthSep.rightEdge, orderLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [repairEventCellView addSubview:labourPriceLabel];
        self.labourPriceLabel = labourPriceLabel;
        
        UIView *eighthSep = [[UIView alloc] initWithFrame:CGRectMake(labourPriceLabel.rightEdge, 0, 1, repairEventCellView.height)];
        eighthSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:eighthSep];

        
        UILabel *workingPriceLabel = [self createLabelWithText:@"" frame:CGRectMake(eighthSep.rightEdge, orderLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [repairEventCellView addSubview:workingPriceLabel];
        self.workingPriceLabel = workingPriceLabel;
        
        UIView *sixthSep = [[UIView alloc] initWithFrame:CGRectMake(workingPriceLabel.rightEdge, 0, 1, repairEventCellView.height)];
        sixthSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:sixthSep];
        
        UILabel *repairTypeLabel = [self createLabelWithText:@"" frame:CGRectMake(sixthSep.rightEdge, orderLabel.y, ActualWidth(85), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairEventCellView addSubview:repairTypeLabel];
        self.repairTypeLabel = repairTypeLabel;
        
        UIView *seventhSep = [[UIView alloc] initWithFrame:CGRectMake(repairTypeLabel.rightEdge, 0, 1, repairEventCellView.height)];
        seventhSep.backgroundColor = BorderColor_Gray;
        [repairEventCellView addSubview:seventhSep];
        
        UILabel *breakdownDiscribeLabel = [self createLabelWithText:@"" frame:CGRectMake(seventhSep.rightEdge, orderLabel.y, ScreenWidth-ActualWidth(40)-repairTypeLabel.rightEdge, ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairEventCellView addSubview:breakdownDiscribeLabel];
        self.breakdownDiscribeLabel = breakdownDiscribeLabel;
    }
    return self;
}

- (void)setupLabelsWithModel:(ICMRepairMaintenanceModel *)model{
    self.model = model;
    self.orderLabel.text = [@(self.order+1) stringValue];
    self.labourPriceLabel.text = model.LABOUR_PRICE;
    self.eventNameLabel.text = model.LABOUR_NAME;
    self.eventNumberLabel.text = model.LABOUR_CODE;
    self.workingTimeLabel.text = model.STD_LABOUR_HOUR;
    self.workingPriceLabel.text = model.LABOUR_AMOUNT;
    self.repairTypeLabel.text = model.REPAIR_TYPE_NAME;
    self.breakdownDiscribeLabel.text = model.TROUBLE_DESC;
}

- (void)setupWorkingTime:(NSString *)workingTime workingPrice:(NSString *)workingPrice{
    self.workingTimeLabel.text = workingTime;
    self.workingPriceLabel.text = workingPrice;
}

- (UILabel *)createLabelWithText:(NSString *)text frame:(CGRect)frame textAlignment:(NSTextAlignment)textAlignment{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = ContentFont;
    label.textColor = ContentTextColor_Black;
    label.textAlignment = textAlignment;
    return label;
}
@end
